home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group00b.txt / 000070_icon-group-sender _Mon Oct 9 08:16:44 2000.msg < prev    next >
Internet Message Format  |  2001-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id IAA00555
  4.     for icon-group-addresses; Mon, 9 Oct 2000 08:14:35 -0700 (MST)
  5. Message-Id: <200010091514.IAA00555@baskerville.CS.Arizona.EDU>
  6. Date: Sat, 7 Oct 2000 08:16:35 -0700
  7. From: Steve Wampler <swampler@noao.edu>
  8. To: David Feustel <dfeustel@mindspring.com>
  9. Cc: icon-group@optima.CS.Arizona.EDU
  10. Subject: Re: Suspend Question
  11. Content-Disposition: inline
  12. User-Agent: Mutt/1.1.9i
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15. Content-Length: 2019
  16.  
  17. On Sat, Oct 07, 2000 at 09:32:59AM -0500, David Feustel wrote:
  18. > I haven't been able to find an answer to these 2 questions
  19. > in any of the Icon/Unicon documentation that I have.
  20. > Can someone enlighten me please?
  21. > How is a procedure that uses suspend to return a result
  22. > invoked so as to continue from the point of suspension?
  23. > How is that procedure 'reset' so that the next value returned
  24. > by the procedure is the first value generated?
  25.  
  26. I assume you're asking how these operations are implemented and
  27. so "Magic" won't suffice...
  28.  
  29. Warning, the following explanation ignores the ugly details:
  30.  
  31. A suspended procedure hasn't gone away - it's stack frame and
  32. surrounding context is still on the execution stack.  If you
  33. picture the execution stack as containing context information
  34. then a procedure call adds an evaluation frame to some context
  35. (e.g. x := a + f(b)
  36. has the stack (growing to the right:
  37.  
  38. x a b
  39.  
  40. at the point of the call of f.  Expressions inside f add
  41. to this context, so the stack looks something like:
  42.  
  43. x a b X Y Z
  44.  
  45. where X Y Z are 'local' context in f.  When f suspends it
  46. hides its local context (which includes the current PC)
  47. So if the suspend is "suspend c", the stack looks like
  48.  
  49. x a b X Y Z PC x a c
  50.  
  51. Note that the information needed to resume f is all there
  52. on the stack, so if backtracking goes back into f, the
  53. stack is quickly reset to
  54.  
  55. x a b X Y Z
  56.  
  57. and the PC can be reset in f to continue at the point of
  58. suspension.  If the goal of the expression evaluation is met,
  59. then the entire context is removed from the stack, including
  60. that part of the context that was 'hidden' by the suspend of f.
  61.  
  62. This is efficient because it turns out that the amount of
  63. context that needs to be copied (the 'x a c' above) is
  64. typically surprisingly small, thanks to the bounded expressions
  65. in Icon.
  66.  
  67. As to 'resetting to start over', there is nothing that needs
  68. to be done this is just another call of the function.
  69.  
  70.  
  71. -- 
  72. --
  73. Steve Wampler-  SOLIS Project, National Solar Observatory
  74. swampler@noao.edu
  75.